package com.servlet;

import com.entity.Students;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/InsertServlet")
public class InsertServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置请求编码格式
        request.setCharacterEncoding("utf-8");
        Insert insert = new Insert();
        Students students = new Students();
        //将请求参数封装至实体对象
        students.setSname(request.getParameter("Sname"));
        students.setSage(request.getParameter("Sage"));
        students.setSclass(request.getParameter("Sclass"));
        //用封装好的实体对象调用sql执行方法
        insert.insert(students);
        response.sendRedirect("/index.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
